
import { request } from 'umi';
import { GetRoleListRequestParams, GetRoleDetailsRequestParams, GetRoleDetailsResponse,RoleDeleteRequestParams,RoleInfoSaveRequestParams,updateRoleMenuRequsetParams} from './data.d';
//查询角色列表
export async function queryRoleList(
    body:GetRoleListRequestParams,
    options?: { [key: string]: any }){
    const {officeId} = body
    return request(
        `/aircaskb/sys/role/getRoles?officeId=${officeId}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}
// 获取角色详情
export async function GetRoleDetailsRequest(
    body: GetRoleDetailsRequestParams, 
    options?: { [key: string]: any }){
    const { roleId } = body;
    return request<AircasKB.ResponseType<GetRoleDetailsResponse>>(
        `/aircaskb/sys/role/getRoleInfo/${roleId}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}
// 保存角色信息
export async function RoleInfoSaveRequest(body:RoleInfoSaveRequestParams, options?: {[key: string]: any}){
    return request(
        `/aircaskb/sys/role/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

// 删除角色
export async function DeleteRoleRequest(
    body: RoleDeleteRequestParams, 
    options?: { [key: string]: any }){
    const { ids } = body;
    return request<AircasKB.ResponseType<GetRoleDetailsResponse>>(
        `/aircaskb/sys/role/delete/${ids}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}

//获取菜单树
export async function getSystemMenuTreeData(options?: {
    [key: string]: any;
}){
    return  request(
        `/aircaskb/sys/menu/getMenuTree`,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            ...(options || {}),
        });
}
// 检查角色中文名称是否可用/sys/role/nameExist
export async function checkedRoleCnName(
    body:{name?:string},
    options?: { [key: string]: any }){
    const {name} = body
    return request(
        `/aircaskb/sys/role/nameExist?name=${name}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}
// 检查角色英文名称是否可用/sys/role/enNameExist
export async function checkedRoleEnName(
    body:{enName?:string},
    options?: { [key: string]: any }){
    const {enName} = body
    return request(
        `/aircaskb/sys/role/enNameExist?enName=${enName}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}

// 修改角色拥有的菜单
export async function updateRoleMenus ( 
    body: updateRoleMenuRequsetParams,
    options?: { [key: string]: any }){
    const {menuIds,roleId} = body
    return request(
        `/aircaskb/sys/role/updateRoleMenus?menuIds=${menuIds}&roleId=${roleId}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}